<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\User\Mapper;

use App\User\Model\UserAccount;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 用户账户表Mapper类
 */
class UserAccountMapper extends AbstractMapper
{
    /**
     * @var UserAccount
     */
    public $model;

    public function assignModel()
    {
        $this->model = UserAccount::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // ID
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 余额
        if (isset($params['balance']) && filled($params['balance'])) {
            $query->where('balance', '=', $params['balance']);
        }

        // 第二余额
        if (isset($params['diamond_balance']) && filled($params['diamond_balance'])) {
            $query->where('diamond_balance', '=', $params['diamond_balance']);
        }

        // 总充值金额
        if (isset($params['pay_money']) && filled($params['pay_money'])) {
            $query->where('pay_money', '=', $params['pay_money']);
        }

        // 提现总金额
        if (isset($params['withdrawal_money']) && filled($params['withdrawal_money'])) {
            $query->where('withdrawal_money', '=', $params['withdrawal_money']);
        }

        // 用户提取次数
        if (isset($params['withdrawal_num']) && filled($params['withdrawal_num'])) {
            $query->where('withdrawal_num', '=', $params['withdrawal_num']);
        }

        // 用户积分
        if (isset($params['points']) && filled($params['points'])) {
            $query->where('points', '=', $params['points']);
        }

        // 幸运值
        if (isset($params['lucky_val']) && filled($params['lucky_val'])) {
            $query->where('lucky_val', '=', $params['lucky_val']);
        }

        // 创建者
        if (isset($params['created_by']) && filled($params['created_by'])) {
            $query->where('created_by', '=', $params['created_by']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 更新时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}